package com.example.springboot_demo2.Service.ServiceImpl;

import com.example.springboot_demo2.Mapper.UserMapper;
import com.example.springboot_demo2.Service.UserService;
import com.example.springboot_demo2.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImp implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void addUser(User user) {

         userMapper.insert(user);
    }

    @Override
    public void deleteUserById(int id) {

       userMapper.deleteById(id);
    }

    @Override
    public void updateUser(User user) {

         userMapper.updateById(user);
    }

    @Override
    public User getUserById(int id) {
       User user = userMapper.selectById(id);
        return user;
    }

    @Override
    public List<User> getAllUsers() {
        List<User> users = userMapper.selectList(null);
        return users;

    }
}
